package com.ct.controller.logs;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.adminlogs.model.po.SysLogSavePO;
import com.ct.application.adminlogs.model.po.SysLogSearchPO;
import com.ct.application.adminlogs.model.vo.SysLogVO;
import com.ct.application.adminlogs.service.ISysLogService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 后台管理-系统日志表
 *
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "系统日志模块",path="/api/v1/adminlogs",code = "C1000",sorted = 9)
public class SysLogController extends BaseController {

    @Autowired
    private ISysLogService adminSysLogService;

    /**
     * 查询系统日志接口
     * @param adminMayaAdvertsSearchPO
     * @return
     */
    @PostMapping("/adminlogs/list")
    @PermissionApi(title = "系统日志表",path="/api/v1/adminlogs/list",code = "C1001",sorted = 1)
    public Page<SysLogVO> findSysLog(@Validated @RequestBody SysLogSearchPO adminMayaAdvertsSearchPO){
        return adminSysLogService.findSysLog(adminMayaAdvertsSearchPO);
    }

    /**
     * 保存和更新
     * @param adminMayaAdvertsSavePO
     * @return
     */
    @PostMapping("/adminlogs/saveupdate")
    @HasAdmin
    @AccessIpLimiter
    public Boolean saveUpdateSysLog(@Validated @RequestBody SysLogSavePO adminMayaAdvertsSavePO){
        return adminSysLogService.saveUpdateSysLog(adminMayaAdvertsSavePO);
    }

    /**
     * 根据id查询系统日志
     * @param id
     * @return
     */
    @PostMapping("/adminlogs/get/{id}")
    @PermissionApi(title = "系统日志表明细",path="/api/v1/adminlogs/get/{id}",code = "C1002",sorted = 2)
    public SysLogVO getSysLogById(@PathVariable("id")Long id){
        return adminSysLogService.getSysLogById(id);
    }

    /**
     * 根据id删除系统日志
     * @param id
     * @return
     */
    @PostMapping("/adminlogs/del/{id}")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除系统日志",path="/api/v1/adminlogs/del/{id}",code = "C1003",sorted = 3)
    public Boolean delSysLogById(@PathVariable("id")Long id){
        return adminSysLogService.deleteSysLogById(id);
    }
}
